package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.fisco.bcos.sdk.abi.ABICodecException;
import org.fisco.bcos.sdk.transaction.model.exception.TransactionBaseException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyArea;
import com.ruoyi.ncpsy.service.INcpsyAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 种植地信管理Controller
 * 
 * @author ruoyi
 * @date 2025-08-09
 */
@RestController
@RequestMapping("/ncpsy/area")
public class NcpsyAreaController extends BaseController
{
    @Autowired
    private INcpsyAreaService ncpsyAreaService;

    /**
     * 查询种植地信管理列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsyArea ncpsyArea)
    {
        startPage();
        System.out.println(ncpsyArea);
        List<NcpsyArea> list = ncpsyAreaService.selectNcpsyAreaList(ncpsyArea);
        return getDataTable(list);
    }

    /**
     * 统计种植地数量
     */
    @GetMapping("/count/{userId}")
    public int list(@PathVariable("userId") Long userId)
    {
        return ncpsyAreaService.selectNcpsyAreaCount(userId);
    }
    /**
     * 导出种植地信管理列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:area:export')")
    @Log(title = "种植地信管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyArea ncpsyArea)
    {
        List<NcpsyArea> list = ncpsyAreaService.selectNcpsyAreaList(ncpsyArea);
        ExcelUtil<NcpsyArea> util = new ExcelUtil<NcpsyArea>(NcpsyArea.class);
        util.exportExcel(response, list, "种植地信管理数据");
    }

    /**
     * 获取种植地信管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(ncpsyAreaService.selectNcpsyAreaByAreaId(areaId));
    }

    /**
     * 新增种植地信管理
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:area:add')")
    @Log(title = "种植地信管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyArea ncpsyArea) throws Exception {
        return toAjax(ncpsyAreaService.insertNcpsyArea(ncpsyArea));
    }

    /**
     * 修改种植地信管理
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:area:edit')")
    @Log(title = "种植地信管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyArea ncpsyArea)
    {
        return toAjax(ncpsyAreaService.updateNcpsyArea(ncpsyArea));
    }

    /**
     * 删除种植地信管理
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:area:remove')")
    @Log(title = "种植地信管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds) throws Exception {
        return toAjax(ncpsyAreaService.deleteNcpsyAreaByAreaIds(areaIds));
    }


}
